package com.csbc.arithmetic.shopping;

import com.csbc.arithmetic.fruit.Fruit;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.Optional;

public class Shopping implements Shop<Fruit> {

//    public static void init(HashMap<String,Fruit> goods){
//        Shopping.goods = goods;
//    }

    private final HashMap<Fruit, Integer> shoppingTrolley = new HashMap<>();
//    private static HashMap<String,Fruit> goods = new HashMap<>();

    @Override
    public void buy(Fruit fruit, Integer weight) {
        if (weight < 0) {
            throw new RuntimeException("购买数量异常");
        }
        shoppingTrolley.compute(fruit, (v, k) -> k == null ? weight : k + weight);

        System.out.println("买了" + fruit.getClass().getSimpleName() + ":" + weight + "斤");

    }

    public HashMap<Fruit, Integer> getShoppingTrolley() {
        return shoppingTrolley;
    }

//    public static HashMap<String, Fruit> getGoods() {
//        return goods;
//    }
}
